home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / SprocketExamples / GlyphaIV / GlyphaIV Sources / G4Interface.c < prev    next >
Encoding:
Text File  |  1998-07-14  |  18.9 KB  |  634 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        G4Interface.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (sjb)    Steve Bollinger
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <2>      7/1/98    sjb        Update to CWPro 2
  25. */
  26.  
  27.  
  28. //============================================================================
  29. //----------------------------------------------------------------------------
  30. //                                    Interface.c
  31. //----------------------------------------------------------------------------
  32. //============================================================================
  33.  
  34. // I put all interface related code in here.  Interface would include event…
  35. // handling, menus, dialog boxes, etc.  All the user interaction that takes…
  36. // place before and after an actual game is in play.
  37.  
  38. #include "G4Externs.h"
  39. #include <Sound.h>
  40. #include <Devices.h>
  41. #include <AppleEvents.h>
  42. #include <ToolUtils.h>
  43.  
  44. #define kAppleMenuID        128
  45. #define iAbout                1
  46. #define kGameMenuID            129
  47. #define iNewGame            1
  48. #define iPauseGame            2
  49. #define iEndGame            3
  50. #define iQuit                5
  51. #define kOptionsMenuID        130
  52. #define iSettings            1
  53. #define iHelp                2
  54. #define iHighScores            3
  55. #define kAboutPictID        132
  56.  
  57.  
  58. void DoAppleMenu (short);
  59. void DoGameMenu (short);
  60. void DoOptionsMenu (short);
  61. void UpdateMainWindow (void);
  62. void HandleMouseEvent (EventRecord *);
  63. void HandleKeyEvent (EventRecord *);
  64. void HandleUpdateEvent (EventRecord *);
  65. void HandleOSEvent (EventRecord *);
  66. void HandleHighLevelEvent (EventRecord *);
  67. void DoAbout (void);
  68. void DoGameSettings (void);
  69. void DrawBanner(void);
  70.  
  71. Rect        mainWindowRect;
  72.  
  73.  
  74. MenuHandle    appleMenu, gameMenu, optionsMenu;
  75. Boolean        switchedOut, quitting, canPlay, openTheScores;
  76.  
  77. extern    prefsInfo    thePrefs;
  78. extern    Rect        backSrcRect, workSrcRect;
  79. extern    CGrafPtr    backSrcMap, workSrcMap;
  80. extern    Boolean        pausing, playing, helpOpen, scoresOpen;
  81.  
  82.  
  83. //==============================================================  Functions
  84. //--------------------------------------------------------------  MenusReflectMode
  85.  
  86. // Depending on whether a game is in progress (paused) or not, I want…
  87. // menu items grayed out in one case and not grayed out in the other.
  88. // This function, when called, displays the menus correctly depending…
  89. // on the mode we're in (playing or not playing, pausing or not).
  90.  
  91. void MenusReflectMode (void)
  92. {
  93.     if (playing)                                // If a game is in progress…
  94.     {
  95.         DisableItem(gameMenu, iNewGame);        // Cannot begin another New Game.
  96.         EnableItem(gameMenu, iPauseGame);        // Can Pause Game.
  97.         if (pausing)                            // If we are paused…
  98.             SetMenuItemText(gameMenu, iPauseGame, 
  99.                     "\pResume Game");            // Rename item "Resume Game".
  100.         else                                    // If we are not paused…
  101.             SetMenuItemText(gameMenu, iPauseGame, 
  102.                     "\pPause Game");            // Rename item "Pause Game".
  103.         EnableItem(gameMenu, iEndGame);            // Can End Game.
  104.         DisableItem(optionsMenu, 0);            // Cannot change game settings.
  105.     }
  106.     else                                        // Else, if Glypha is idle…
  107.     {
  108.         EnableItem(gameMenu, iNewGame);            // Can begin a New Game.
  109.         DisableItem(gameMenu, iPauseGame);        // Cannot Pause Game.
  110.         SetMenuItemText(gameMenu, iPauseGame, 
  111.                 "\pPause Game");                // Rename item "Pause Game".
  112.         DisableItem(gameMenu, iEndGame);        // Cannot End Game.
  113.         EnableItem(optionsMenu, 0);                // Can change game settings.
  114.     }
  115. }
  116.  
  117. //--------------------------------------------------------------  DoAppleMenu
  118.  
  119. // This function takes care of handling the Apple menu (Desk Assecories and the…
  120. // About box).
  121.  
  122. void DoAppleMenu (short theItem)
  123. {
  124.     Str255        daName;
  125.     GrafPtr        wasPort;
  126.     short        daNumber;
  127.     
  128.     switch (theItem)                            // Depending on the item selected…
  129.     {
  130.         case iAbout:                            // If the About item was selected…
  131.         if ((scoresOpen) || (helpOpen))            // If high scores or help screens up…
  132.         {
  133.             CloseWall();                        // hide them.
  134.             scoresOpen = FALSE;                    // High scores no longer open.
  135.             helpOpen = FALSE;                    // Help screen is no longer open.
  136.                                                 // Uncheck help & high scores menu items.
  137.             CheckItem(optionsMenu, iHelp, helpOpen);
  138.             CheckItem(optionsMenu, iHighScores, scoresOpen);
  139.         }
  140.         DoAbout();                                // Bring up the About dialog.
  141.         break;
  142.         
  143.         default:                                // If any other item was selected (DA)…
  144.         GetMenuItemText(appleMenu, theItem, daName);    // Get the name of the item selected.
  145.         GetPort(&wasPort);                        // Remember our port.
  146.         daNumber = OpenDeskAcc(daName);            // Launch the Desk Accesory.
  147.         SetPort((GrafPtr)wasPort);                // When we return, restore port.
  148.         break;
  149.     }
  150. }
  151.  
  152. //--------------------------------------------------------------  DoGameMenu
  153.  
  154. // This function handles a users interaction with the Game menu.  Quitting…
  155. // Glypha, starting a new game, resuming a paused game are handled here.
  156.  
  157. void DoGameMenu (short theItem)
  158. {
  159.     switch (theItem)                        // Depending on menu item selected…
  160.     {
  161.         case iNewGame:                        // If user selected New Game item…
  162.         if ((scoresOpen) || (helpOpen))        // If high scores or help screen is up,…
  163.         {                                    // close them first.
  164.             CloseWall();
  165.             scoresOpen = FALSE;
  166.             helpOpen = FALSE;
  167.             CheckItem(optionsMenu, iHelp, helpOpen);
  168.             CheckItem(optionsMenu, iHighScores, scoresOpen);
  169.         }
  170.         InitNewGame();                        // Initialize variables for a new game.
  171.         MenusReflectMode();                    // Properly gray out the right menu items.
  172.         break;
  173.         
  174.         case iPauseGame:                    // If user selected Pause Game item…
  175.         if (pausing)                        // If we are paused, resume playing.
  176.         {
  177.             pausing = FALSE;                // Turn off pausing flag.
  178.             DumpBackToWorkMap();            // Restore off screen just in case.
  179.         }                                    // Actually pausing a game (not resuming)…
  180.         break;                                // is not really handled here.  It's handled…
  181.                                             // directly within the main game loop.
  182.                                             
  183.         case iEndGame:                        // Ending a game in progress isn't really…
  184.         break;                                // handled here - this is a dummy item.
  185.                                             // Ending a game is handled within the main…
  186.                                             // game loop by looking for the 'command'…
  187.                                             // and 'E' key explicitly.
  188.         
  189.         case iQuit:                            // If user selected Quit item…
  190.         quitting = TRUE;                    // Set quitting flag to TRUE.
  191.         break;
  192.     }
  193. }
  194.  
  195. //--------------------------------------------------------------  DoOptionsMenu
  196.  
  197. // This function handles the Options menu.  Options include game settings,…
  198. // displaying the high scores, and bringing up the Help screen.
  199.  
  200. void DoOptionsMenu (short theItem)
  201. {
  202.     switch (theItem)                    // Depending on which item the user selected…
  203.     {
  204.         case iSettings:                    // If user selected Game Settings item…
  205.         if ((scoresOpen) || (helpOpen))    // Close high scores or help screen.
  206.         {
  207.             CloseWall();
  208.             scoresOpen = FALSE;
  209.             helpOpen = FALSE;
  210.             CheckItem(optionsMenu, iHelp, helpOpen);
  211.             CheckItem(optionsMenu, iHighScores, scoresOpen);
  212.         }
  213.         DoGameSettings();                // Bring up game settings dialog.
  214.         break;
  215.         
  216.         case iHelp:                        // If user selected Help item…
  217.         if (helpOpen)                    // If Help open, close it.
  218.         {
  219.             CloseWall();
  220.             helpOpen = FALSE;
  221.         }
  222.         else                            // Else, if Help is not open - open it.
  223.         {
  224.             if (scoresOpen)                // If the High Scores are up though,…
  225.             {
  226.                 CloseWall();            // Close them first.
  227.                 scoresOpen = FALSE;
  228.                 CheckItem(optionsMenu, iHighScores, scoresOpen);
  229.             }
  230.             OpenHelp();                    // Now open the Help screen.
  231.         }
  232.         CheckItem(optionsMenu, iHelp, helpOpen);
  233.         break;
  234.         
  235.         case iHighScores:                // If user selected High Scores…
  236.         if (scoresOpen)                    // If the High Scores are up, close them.
  237.         {
  238.             CloseWall();
  239.             scoresOpen = FALSE;
  240.         }
  241.         else                            // If the High Scores are not up…
  242.         {
  243.             if (helpOpen)                // First see if Help is open.
  244.             {
  245.                 CloseWall();            // And close the Help screen.
  246.                 helpOpen = FALSE;
  247.                 CheckItem(optionsMenu, iHelp, helpOpen);
  248.             }
  249.             OpenHighScores();            // Now open the High Scores.
  250.         }
  251.         CheckItem(optionsMenu, iHighScores, scoresOpen);
  252.         break;
  253.     }
  254. }
  255.  
  256. //--------------------------------------------------------------  DoMenuChoice
  257.  
  258. // This is the main menu-handling function.  It examines which menu was selected…
  259. // by the user and passes on to the appropriate function, the item within that…
  260. // menu that was selected.
  261.  
  262. void DoMenuChoice (long menuChoice)
  263. {
  264.     short        theMenu, theItem;
  265.     
  266.     if (menuChoice == 0)            // A little error checking.
  267.         return;
  268.     
  269.     theMenu = HiWord(menuChoice);    // Extract which menu was selected.
  270.     theItem = LoWord(menuChoice);    // Extract which item it was that was selected.
  271.     
  272.     switch (theMenu)                // Now, depending upon which menu was selected…
  273.     {
  274.         case kAppleMenuID:            // If the Apple menu selected…
  275.         DoAppleMenu(theItem);        // Call the function that handles the Apple menu.
  276.         break;
  277.         
  278.         case kGameMenuID:            // If the Game menu selected…
  279.         DoGameMenu(theItem);        // Call the function that handles the Game menu.
  280.         break;
  281.         
  282.         case kOptionsMenuID:        // If the Options menu selected…
  283.         DoOptionsMenu(theItem);        // Call the function that handles the Options menu.
  284.         break;
  285.     }
  286.     
  287.     HiliteMenu(0);                    // "De-invert" menu.
  288. }
  289.  
  290. //--------------------------------------------------------------  UpdateMainWindow
  291.  
  292. // This is a simple function that simply copies the contents from the…
  293. // background offscreen pixmap to the main screen.  It is primarily…
  294. // called in response to an update event, but could be called any time…
  295. // when I want to force the screen to be redrawn.
  296.  
  297. void UpdateMainWindow (void)
  298. {
  299.     OSStatus theError;
  300.     
  301.     theError = DSpContext_GetBackBuffer( gTheContext, kDSpBufferKind_Normal, &workSrcMap );
  302.     if( theError )
  303.     {
  304.         DSpContext_Release( gTheContext );
  305.         gTheContext = NULL;
  306.         RedAlert("\pUnable to get back buffer");
  307.     }
  308.  
  309.     CopyBits(&((GrafPtr)backSrcMap)->portBits, 
  310.             &(((GrafPtr)workSrcMap)->portBits), 
  311.             &mainWindowRect, &mainWindowRect, 
  312.             srcCopy, 0L);
  313.  
  314.     DSpContext_SwapBuffers( gTheContext, NULL, NULL );
  315. }
  316.  
  317. //--------------------------------------------------------------  HandleMouseEvent
  318.  
  319. // Mouse clicks come here.  This is standard event-handling drivel.  No different 
  320. // from any other standard Mac program (game or otherwise).
  321.  
  322. void HandleMouseEvent (EventRecord *theEvent)
  323. {
  324.     WindowPtr    whichWindow;
  325.     long        menuChoice;
  326.     short        thePart;
  327.                                                 // Determine window and where in window.
  328.     thePart = FindWindow(theEvent->where, &whichWindow);
  329.     
  330.     switch (thePart)                            // Depending on where mouse was clicked…
  331.     {
  332.         case inSysWindow:                        // In a Desk Accesory.
  333.         SystemClick(theEvent, whichWindow);        // (Is this stuff obsolete yet?)
  334.         break;
  335.         
  336.         case inMenuBar:                            // Selected a menu item.
  337.         menuChoice = MenuSelect(theEvent->where);
  338.         if (canPlay)                            // Call menu handling routine.
  339.             DoMenuChoice(menuChoice);
  340.         break;
  341.         
  342.         case inDrag:                            // Like the lazy bastard I am…
  343.         case inGoAway:                            // I'll just ignore these.
  344.         case inGrow:                            // But, hey, the window isn't…
  345.         case inZoomIn:                            // movable or growable!
  346.         case inZoomOut:
  347.         break;
  348.         
  349.         case inContent:                            // Click in the window itself.
  350.         if (!playing)
  351.         {
  352.             short h = theEvent->where.h;
  353.             short v = theEvent->where.v;
  354.             short count = 10;
  355.             
  356.             while(count > 0)
  357.             {
  358.                 StartPixelShatter(h, v, 0, 0, kShatterLightningDust);
  359.                 count--;
  360.             }
  361.             
  362.             lightH = h;
  363.             lightV = v;
  364.             lightningCount = 15;
  365.             PlayExternalSound(kLightningSound, kLightningPriority);
  366.         }
  367.         break;
  368.     }
  369. }
  370.  
  371. //--------------------------------------------------------------  HandleKeyEvent
  372.  
  373. // More standard issue.  This function handles any keystrokes when no game is
  374. // in session.  Command-key strokes handled here too.
  375.  
  376. void HandleKeyEvent (EventRecord *theEvent)
  377. {
  378.     char        theChar;
  379.     Boolean        commandDown;
  380.     
  381.     theChar = theEvent->message & charCodeMask;                // Extract key hit.
  382.     commandDown = ((theEvent->modifiers & cmdKey) != 0);    // See if command key down.
  383.     
  384.     if (commandDown)                                // If command key down, call menu…
  385.     {                                                // handling routine.
  386.         if (canPlay)
  387.             DoMenuChoice(MenuKey(theChar));
  388.     }
  389.     else
  390.     {
  391.         if (helpOpen)                                // Handle special keys if the help…
  392.         {                                            // screen is up.
  393.             if (theChar == kUpArrowKeyASCII)        // Up arrow key scrolls help down.
  394.             {
  395.                 if (theEvent->what == autoKey)
  396.                     ScrollHelp(-3);
  397.                 else
  398.                     ScrollHelp(-1);
  399.             }
  400.             else if (theChar == kDownArrowKeyASCII)    // Down arrow key scrolls help up.
  401.             {
  402.                 if (theEvent->what == autoKey)
  403.                     ScrollHelp(3);
  404.                 else
  405.                     ScrollHelp(1);
  406.             }
  407.             else if (theChar == kPageDownKeyASCII)    // Handle page down for help screen.
  408.             {
  409.                 ScrollHelp(199);
  410.             }
  411.             else if (theChar == kPageUpKeyASCII)    // Handle page up for help.
  412.             {
  413.                 ScrollHelp(-199);
  414.             }
  415.             else if ((theChar == kHelpKeyASCII) && (!playing))
  416.             {                                        // Hitting Help key closes help…
  417.                 CloseWall();                        // (if it's already open).
  418.                 helpOpen = FALSE;
  419.                 CheckItem(optionsMenu, iHelp, helpOpen);
  420.             }
  421.         }
  422.         else if ((theChar == kHelpKeyASCII) && (!playing))
  423.         {                                            // Else, if help not open and Help…
  424.             if (scoresOpen)                            // key is hit, open Help.
  425.             {                                        // Close high scores if open.
  426.                 CloseWall();
  427.                 scoresOpen = FALSE;
  428.                 CheckItem(optionsMenu, iHighScores, scoresOpen);
  429.             }
  430.             OpenHelp();                                // Open help.
  431.             CheckItem(optionsMenu, iHelp, helpOpen);
  432.         }
  433.     }
  434. }
  435.  
  436. //--------------------------------------------------------------  HandleUpdateEvent
  437.  
  438. // This function handles update events.  Standard event-handling stuff.
  439.  
  440. void HandleUpdateEvent (EventRecord *theEvent)
  441. {    
  442. #if !GENERATINGPOWERPC
  443.     if ((WindowPtr)theEvent->message == mainWindow)
  444.     {
  445.         SetPort((GrafPtr)mainWindow);        // Don't forget this line, BTW.
  446.         BeginUpdate((GrafPtr)mainWindow);    // I did once and it took me…
  447.         UpdateMainWindow();                    // ages to track down that bug.
  448.         EndUpdate((GrafPtr)mainWindow);        // Well, it took me a week I think.
  449.         canPlay = TRUE;
  450.     }
  451. #endif
  452. }
  453.  
  454. //--------------------------------------------------------------  HandleOSEvent
  455.  
  456. // Handle switchin in and out events.  Standard event-handling stuff.
  457.  
  458. void HandleOSEvent (EventRecord *theEvent)
  459. {    
  460.     if (theEvent->message & 0x01000000)        // If suspend or resume event…
  461.     {
  462.         if (theEvent->message & 0x00000001)    // Specifically, if resume event…
  463.             switchedOut = FALSE;            // I keep thinking I should do more here.
  464.         else                                // Or if suspend event…
  465.             switchedOut = TRUE;                // What am I forgetting?
  466.     }
  467. }
  468.  
  469. //--------------------------------------------------------------  HandleHighLevelEvent
  470.  
  471. // Again, it's a fact I'm lazy.  AppleEvents are fairly easy to implement but…
  472. // a nightmare to try and explain.  Filling out the below function is left as…
  473. // and exercise to the reader.
  474.  
  475. void HandleHighLevelEvent (EventRecord *theEvent)
  476. {    
  477. //    theErr = AEProcessAppleEvent(theEvent);
  478. }
  479.  
  480. //--------------------------------------------------------------  HandleEvent
  481.  
  482. // Standard event stuff.  This is the culling function that calls all the above…
  483. // functions.  It looks for an event and if it detects one, it calls the appropriate…
  484. // function above to handle it.
  485.  
  486. void HandleEvent (void)
  487. {
  488.     EventRecord    theEvent;
  489.     long        sleep = 0L;
  490.     Boolean        itHappened;
  491.                                             // See if an event is queued up.
  492. #if GENERATINGPOWERPC
  493.         canPlay = TRUE;
  494. #endif
  495.  
  496.     itHappened = WaitNextEvent(everyEvent, &theEvent, sleep, 0L);
  497.     
  498.     if (itHappened)                            // Ah, an event.  I live for events!
  499.     {
  500.         switch (theEvent.what)                // And what kind of event be ya'?
  501.         {
  502.             case mouseDown:                    // Aiy!  Y' be a mouse click do ya'?
  503.             HandleMouseEvent(&theEvent);
  504.             break;
  505.             
  506.             case keyDown:                    // Key down, key held down events.
  507.             case autoKey:
  508.             HandleKeyEvent(&theEvent);
  509.             break;
  510.             
  511.             case updateEvt:                    // Something needs redrawing!
  512.             HandleUpdateEvent(&theEvent);
  513.             break;
  514.             
  515.             case osEvt:                        // Switching in and out events.
  516.             HandleOSEvent(&theEvent);
  517.             break;
  518.             
  519.             case kHighLevelEvent:            // Hmmmm.  A "what" event?
  520.             HandleHighLevelEvent(&theEvent);
  521.             break;
  522.             
  523.             default:
  524.             break;
  525.         }
  526.     }
  527.     
  528.  
  529. #if 0
  530.     else if (openTheScores)                    // Check for "auto open" flag.
  531.     {                                        // If TRUE, set the flag back to…
  532.         openTheScores = FALSE;                // FALSE and open the high scores.
  533.         OpenHighScores();
  534.     }
  535. #endif
  536. }
  537.  
  538. //--------------------------------------------------------------  DoAbout
  539.  
  540. // This handles the About dialog.  It brings up the About box in a…
  541. // simple centered window with no drag bar, close box or anything.
  542. // Leaving the dialog is handled with a simple mouse click.
  543.  
  544. void DoAbout (void)
  545. {
  546.     Rect        aboutRect;
  547.     WindowPtr    aboutWindow;
  548.     
  549.     SetRect(&aboutRect, 0, 0, 325, 318);        // Bring up centered window.
  550.     CenterRectInRect(&aboutRect, &qd.screenBits.bounds);
  551.     aboutWindow = GetNewCWindow(129, 0L, kPutInFront);
  552.     MoveWindow((GrafPtr)aboutWindow, aboutRect.left, aboutRect.top, TRUE);
  553.     ShowWindow((GrafPtr)aboutWindow);
  554.     SetPort((GrafPtr)aboutWindow);
  555.     LoadGraphic(kAboutPictID);                    // Draw About dialog graphic.
  556.     
  557.     do                                            // Make sure button not down…
  558.     {                                            // before proceeding.
  559.     }
  560.     while (Button());                            // Proceed.
  561.     do                                            // And now wait until the mouse…
  562.     {                                            // is pressed before closing the…
  563.     }                                            // window (ABout dialog).
  564.     while (!Button());
  565.     
  566.     FlushEvents(everyEvent, 0);                    // Flush the queue.
  567.     
  568.     if (aboutWindow != 0L)
  569.         DisposeWindow(aboutWindow);                // Close the About dialog.
  570. }
  571.  
  572. //--------------------------------------------------------------  DoGameSettings
  573.  
  574. // This one however is a good and proper dialog box.  It handles the meager…
  575. // preference settings for Glypha.  Nothing fancy here to report.  Just a…
  576. // straight-forward dialog calling routine.
  577.  
  578. void DoGameSettings (void)
  579. {
  580.     #define        kGameSettingsDialogID    133
  581.     DialogPtr    theDial;
  582.     long        newVolume;
  583.     short        i, item;
  584.     Boolean        leaving;
  585.     
  586.     CenterDialog(kGameSettingsDialogID);    // Center dialog, then call up.
  587.     theDial = GetNewDialog(kGameSettingsDialogID, 0L, kPutInFront);
  588.     SetPort((GrafPtr)theDial);
  589.     ShowWindow((GrafPtr)theDial);            // Make visible (after centering).
  590.     DrawDefaultButton(theDial);                // Draw border around Okay button.
  591.     FlushEvents(everyEvent, 0);
  592.                                             // Put in a default sound volume.
  593.     SetDialogNumToStr(theDial, 3, (long)thePrefs.wasVolume);
  594.     SelectDialogItemText(theDial, 3, 0, 1024);    // Select it.
  595.     
  596.     leaving = FALSE;
  597.     
  598.     while (!leaving)
  599.     {
  600.         ModalDialog(0L, &item);                // Simple modal dialog filtering.
  601.         
  602.         if (item == 1)                        // Did user hit the Okay button?
  603.         {                                    // Well see if volume entered is legal.
  604.             GetDialogNumFromStr(theDial, 3, &newVolume);
  605.             if ((newVolume >= 0) && (newVolume <= 7))
  606.             {                                // If it is legal, we'll note it and quit.
  607.                 thePrefs.wasVolume = (short)newVolume;
  608.                 SetSoundVol((short)newVolume);
  609.                 leaving = TRUE;                // Bye.
  610.             }
  611.             else                            // Otherwise, the volume entered is wrong.
  612.             {                                // So we'll Beep, enter the last legal…
  613.                 SysBeep(1);                    // value and select the text again.
  614.                 SetDialogNumToStr(theDial, 3, (long)thePrefs.wasVolume);
  615.                 SelectDialogItemText(theDial, 3, 0, 1024);
  616.             }
  617.         }
  618.         else if (item == 2)                    // Did the user hit the "Clear Scores"…
  619.         {                                    // button?
  620.             for (i = 0; i < 10; i++)        // Walk through and zero scores.
  621.             {
  622.                 PasStringCopy("\pNemo", thePrefs.highNames[i]);
  623.                 thePrefs.highScores[i] = 0L;
  624.                 thePrefs.highLevel[i] = 0;
  625.                 openTheScores = TRUE;        // Bring up scores when dialog quits.
  626.             }
  627.             DisableControl(theDial, 2);        // Gray out Clear Scores button.
  628.         }
  629.     }
  630.     
  631.     DisposeDialog(theDial);                    // Clean up before going.
  632. }
  633.  
  634.